package com.example.basic.configinfo;

import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;

import com.umeng.commonsdk.UMConfigure;

import java.util.Arrays;

public class DeviceInfo {

    private static final String TAG = "DeviceInfo";

    private static String mDeviceId = "";
    private static String mMac = "";

    public static String getAndroidVersion() {
        return String.valueOf(Build.VERSION.SDK_INT);
    }

    public static String getBrand() {
        return Build.MANUFACTURER;
    }

    public static String getProduct() {
        return Build.PRODUCT;
    }

    public static String getSupportedABIS() {
        return Arrays.toString(Build.SUPPORTED_ABIS);
    }

    public static String getDevice() {
        return Build.DEVICE;
    }

    public static String getDisplayInfo() {
        return Build.DISPLAY;
    }

    public static String getDeviceModel() {
        return Build.MODEL;
    }

    public static void init(Context context) {
        if (TextUtils.isEmpty(mDeviceId)) {
            //需要集成友盟的SDK
            String[] testDeviceInfo = UMConfigure.getTestDeviceInfo(context);
            if (testDeviceInfo.length > 1) {
                mDeviceId = testDeviceInfo[0];
                mMac = testDeviceInfo[1];
                Log.i(TAG, "UM device id : " + testDeviceInfo[0] + " UM device MAC : " + testDeviceInfo[1]);

                if (TextUtils.isEmpty(mDeviceId)) {
                    mDeviceId = "";
                }

                if (TextUtils.isEmpty(mMac)) {
                    mMac = "";
                }
            }
        }
    }

    public static String getDeviceInfoStr() {
        return "安卓版本：" + getAndroidVersion() + "\n" +
                "手机厂商：" + getBrand() + "\n" +
                "手机品牌：" + getProduct() + "\n" +
                "设备ID：" + mDeviceId + "\n" +
                "Mac地址：" + mMac + "\n" +
                "支持的cpu型号：" + getSupportedABIS() + "\n" +
                "手机型号：" + getDevice() + "\n" +
                "显示信息：" + getDisplayInfo() + "\n" +
                "设备型号：" + getDeviceModel();
    }
}
